# Definition for a binary tree node.
class TreeNode:
  def __init__(self, x):
    self.val = x
    self.left = None
    self.right = None


class Solution:
  def levelOrder(self, root: TreeNode) -> list:
    if not root:
      return []
    res, qwq = [], [(root, 0)]
    while len(qwq) > 0:
      node, level = qwq.pop(0)
      if level >= len(res):
        res.append(list())
      if node:
        res[level].append(node.val)
      if node.left:
        qwq.append((node.left, level+1))
      if node.right:
        qwq.append((node.right, level+1))
    if len(res) == 1:
      return res
    for i in range(1, len(res), 2):
      res[i].reverse()
    return res


def stringToTreeNode(input):
  input = input.strip()
  input = input[1:-1]
  if not input:
    return None

  inputValues = [s.strip() for s in input.split(',')]
  root = TreeNode(int(inputValues[0]))
  nodeQueue = [root]
  front = 0
  index = 1
  while index < len(inputValues):
    node = nodeQueue[front]
    front = front + 1

    item = inputValues[index]
    index = index + 1
    if item != "null":
      leftNumber = int(item)
      node.left = TreeNode(leftNumber)
      nodeQueue.append(node.left)

    if index >= len(inputValues):
      break

    item = inputValues[index]
    index = index + 1
    if item != "null":
      rightNumber = int(item)
      node.right = TreeNode(rightNumber)
      nodeQueue.append(node.right)
  return root


def integerListToString(nums, len_of_list=None):
  import json
  if not len_of_list:
    len_of_list = len(nums)
  return json.dumps(nums[:len_of_list])


def main():
  import sys
  import io

  def readlines():
    for line in io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8'):
      yield line.strip('\n')

  lines = readlines()
  while True:
    try:
      line = next(lines)
      root = stringToTreeNode(line)

      ret = Solution().levelOrder(root)

      out = integerListToString(ret)
      print(out)
    except StopIteration:
      break


'''
STATUS: SOLVED
TRIES:  1
TIME:   56 MS
MEMORY: 13.7 MB
'''
if __name__ == '__main__':
  main()
